﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace Taste.Demos.Silverlight.DataModel
{
    public class Customer : INotifyPropertyChanged
    {
        private string _FirstName;
        public string FirstName
        {
            get { return _FirstName; }
            set
            {
                if(_FirstName != value)
                {
                    _FirstName = value;
                    RaisePropertyChanged("FirstName");
                    CheckValidity();
                }
            }
        }

        private string _LastName;
        public string LastName
        {
            get { return _LastName; }
            set
            {
                if(_LastName != value)
                {
                    _LastName = value;
                    RaisePropertyChanged("LastName");
                    CheckValidity();
                }
            }
        }

        private bool _IsValid;
        public bool IsValid
        {
            get { return _IsValid; }
            set { if(_IsValid != value) { _IsValid = value; RaisePropertyChanged("IsValid"); } }
        }

        private void CheckValidity()
        {
            this.IsValid = !string.IsNullOrEmpty(this.LastName) && !string.IsNullOrEmpty(this.FirstName);
        }

        #region INotifyPropertyChanged members
        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            if(this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}
